package com.simon.hse.activity.danger;

import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bigkoo.pickerview.builder.TimePickerBuilder;
import com.bigkoo.pickerview.listener.OnTimeSelectListener;
import com.bigkoo.pickerview.view.TimePickerView;
import com.google.gson.Gson;
import com.simon.hse.MyApplication;
import com.simon.hse.R;
import com.simon.hse.activity.BaseActivity;
import com.simon.hse.adapter.CommonEmptyAdapter;
import com.simon.hse.adapter.CommonViewHolder;
import com.simon.hse.http.CommonCallBack;
import com.simon.hse.http.HttpManager;
import com.simon.hse.http.entity.DangerStopDetailOutput;
import com.simon.hse.http.entity.DropDownInput;
import com.simon.hse.http.entity.DropDownOutput;
import com.simon.hse.http.entity.TrainPersonOutput;
import com.simon.hse.utils.DateTimeUtils;
import com.simon.hse.utils.PopupWindowUtils;
import com.simon.hse.utils.ToastUtils;
import com.zhy.view.flowlayout.FlowLayout;
import com.zhy.view.flowlayout.TagAdapter;
import com.zhy.view.flowlayout.TagFlowLayout;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.Event;
import org.xutils.view.annotation.ViewInject;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Set;

import retrofit2.Call;

/**
 * STOP安全沟通卡
 */
@SuppressWarnings("all")
@ContentView(R.layout.activity_danger_stop_detail)
public class DangerStopDetailActivity extends BaseActivity {
    @ViewInject(R.id.tv_common_title)
    TextView mTv_common_title;

    @ViewInject(R.id.tv_danger_stop_safe)
    TextView mTv_danger_stop_safe;

    @ViewInject(R.id.tv_danger_stop_obsever)
    TextView mTv_danger_stop_obsever;

    @ViewInject(R.id.tv_danger_stop_department)
    TextView mTv_danger_stop_department;

    @ViewInject(R.id.tv_danger_stop_day)
    TextView mTv_danger_stop_day;

    @ViewInject(R.id.tv_danger_stop_area)
    TextView mTv_danger_stop_area;

    @ViewInject(R.id.tv_danger_stop_date)
    TextView mTv_danger_stop_date;

    @ViewInject(R.id.ll_danger_stop_safe)
    LinearLayout mLl_danger_stop_safe;

    @ViewInject(R.id.ll_danger_stop_obsever)
    LinearLayout mLl_danger_stop_obsever;

    @ViewInject(R.id.ll_danger_stop_department)
    LinearLayout mLl_danger_stop_department;

    @ViewInject(R.id.ll_danger_stop_day)
    LinearLayout mLl_danger_stop_day;

    @ViewInject(R.id.ll_danger_stop_area)
    LinearLayout mLl_danger_stop_area;

    @ViewInject(R.id.ll_danger_stop_date)
    LinearLayout mLl_danger_stop_date;

    @ViewInject(R.id.tv_tab_flow_ryfy_other)
    TextView mTv_tab_flow_ryfy_other;

    @ViewInject(R.id.et_tab_flow_ryfy_other)
    EditText mEt_tab_flow_ryfy_other;

    @ViewInject(R.id.flowlayout_ryfy)
    TagFlowLayout mFlowlayout_ryfy;

    @ViewInject(R.id.tv_tab_flow_ryfh_other)
    TextView mTv_tab_flow_ryfh_other;

    @ViewInject(R.id.et_tab_flow_ryfh_other)
    EditText mEt_tab_flow_ryfh_other;

    @ViewInject(R.id.flowlayout_ryfh)
    TagFlowLayout mFlowlayout_ryfh;

    @ViewInject(R.id.tv_tab_flow_rywz_other)
    TextView mTv_tab_flow_rywz_other;

    @ViewInject(R.id.et_tab_flow_rywz_other)
    EditText mEt_tab_flow_rywz_other;

    @ViewInject(R.id.flowlayout_rywz)
    TagFlowLayout mFlowlayout_rywz;

    @ViewInject(R.id.tv_tab_flow_gjsb_other)
    TextView mTv_tab_flow_gjsb_other;

    @ViewInject(R.id.et_tab_flow_gjsb_other)
    EditText mEt_tab_flow_gjsb_other;

    @ViewInject(R.id.flowlayout_gjsb)
    TagFlowLayout mFlowlayout_gjsb;

    @ViewInject(R.id.tv_tab_flow_cx_other)
    TextView mTv_tab_flow_cx_other;

    @ViewInject(R.id.et_tab_flow_cx_other)
    EditText mEt_tab_flow_cx_other;

    @ViewInject(R.id.flowlayout_cx)
    TagFlowLayout mFlowlayout_cx;

    @ViewInject(R.id.tv_tab_flow_cxbz_other)
    TextView mTv_tab_flow_cxbz_other;

    @ViewInject(R.id.et_tab_flow_cxbz_other)
    EditText mEt_tab_flow_cxbz_other;

    @ViewInject(R.id.flowlayout_cxbz)
    TagFlowLayout mFlowlayout_cxbz;

    @ViewInject(R.id.et_danger_stop_safe)
    EditText mEt_danger_stop_safe;

    @ViewInject(R.id.et_danger_stop_not_safe)
    EditText mEt_danger_stop_not_safe;

    @ViewInject(R.id.ll_danger_stop_bottom)
    LinearLayout mLl_danger_stop_bottom;

    private String id;
    private boolean evaluationc;// 是否皆安全
    private String observePeopleId;// 观察人
    private String departmentId;// 部门
    private String shiftsId;// 班次
    private String situationId;// 区域
    private String ryfy_remark;// 人员反映
    private String ryfh_remark;// 个人防护装备
    private String rywz_remark;// 人员的位置
    private String gjsb_remark;// 工具及设备
    private String cx_remark;// 程序
    private String cxbz_remark;// 秩序标准
    private boolean isShowBottom = false;
    private List<DropDownOutput.DataBean.DataDicListBean.ValueBean> mDangerRyfyList = new ArrayList<>();// 人员反映
    private List<DropDownOutput.DataBean.DataDicListBean.ValueBean> mDangerRyfhList = new ArrayList<>();// 个人防护装备
    private List<DropDownOutput.DataBean.DataDicListBean.ValueBean> mDangerRywzList = new ArrayList<>();// 人员的位置
    private List<DropDownOutput.DataBean.DataDicListBean.ValueBean> mDangerGjsbList = new ArrayList<>();// 工具及设备
    private List<DropDownOutput.DataBean.DataDicListBean.ValueBean> mDangerCxList = new ArrayList<>();// 程序
    private List<DropDownOutput.DataBean.DataDicListBean.ValueBean> mDangerCxbzList = new ArrayList<>();// 秩序标准

    private TagAdapter<DropDownOutput.DataBean.DataDicListBean.ValueBean> mTagRyfyAdapter;// 人员反映
    private TagAdapter<DropDownOutput.DataBean.DataDicListBean.ValueBean> mTagRyfhAdapter;// 个人防护装备
    private TagAdapter<DropDownOutput.DataBean.DataDicListBean.ValueBean> mTagRywzAdapter;// 人员的位置
    private TagAdapter<DropDownOutput.DataBean.DataDicListBean.ValueBean> mTagGjsbAdapter;// 工具及设备
    private TagAdapter<DropDownOutput.DataBean.DataDicListBean.ValueBean> mTagCxAdapter;// 程序
    private TagAdapter<DropDownOutput.DataBean.DataDicListBean.ValueBean> mTagCxbzAdapter;// 秩序标准

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mTv_common_title.setText("STOP安全沟通卡");
        Bundle bundle = getIntent().getExtras();
        if (bundle == null) {
            mLl_danger_stop_bottom.setVisibility(View.VISIBLE);
            initOptions(9040);
            initOptions(9041);
            initOptions(9042);
            initOptions(9043);
            initOptions(9044);
            initOptions(9045);
        } else {
            id = bundle.getString("ID");
            initStopDetail();
            mLl_danger_stop_bottom.setVisibility(View.INVISIBLE);
        }

        Drawable drawable = getResources().getDrawable(R.drawable.cb_examination_bg);
        drawable.setBounds(0, 0, 45, 45);
        mTv_tab_flow_ryfy_other.setCompoundDrawables(drawable, null, null, null);
        mTv_tab_flow_ryfy_other.setCompoundDrawablePadding(10);
        mTv_tab_flow_ryfh_other.setCompoundDrawables(drawable, null, null, null);
        mTv_tab_flow_ryfh_other.setCompoundDrawablePadding(10);
        mTv_tab_flow_rywz_other.setCompoundDrawables(drawable, null, null, null);
        mTv_tab_flow_rywz_other.setCompoundDrawablePadding(10);
        mTv_tab_flow_gjsb_other.setCompoundDrawables(drawable, null, null, null);
        mTv_tab_flow_gjsb_other.setCompoundDrawablePadding(10);
        mTv_tab_flow_cx_other.setCompoundDrawables(drawable, null, null, null);
        mTv_tab_flow_cx_other.setCompoundDrawablePadding(10);
        mTv_tab_flow_cxbz_other.setCompoundDrawables(drawable, null, null, null);
        mTv_tab_flow_cxbz_other.setCompoundDrawablePadding(10);

    }

    @Event(value = {R.id.iv_common_left
            , R.id.ll_danger_stop_safe, R.id.ll_danger_stop_obsever, R.id.ll_danger_stop_department
            , R.id.ll_danger_stop_day, R.id.ll_danger_stop_area, R.id.ll_danger_stop_date
            , R.id.ll_tab_flow_ryfy_other, R.id.ll_tab_flow_ryfh_other, R.id.ll_tab_flow_rywz_other
            , R.id.ll_tab_flow_gjsb_other, R.id.ll_tab_flow_cx_other, R.id.ll_tab_flow_cxbz_other})
    private void finish(View view) {
        switch (view.getId()) {
            case R.id.iv_common_left:
                finish();
                break;
            case R.id.ll_danger_stop_safe:
                initSafePop();
                break;
            case R.id.ll_danger_stop_obsever:
                initObserverPop();
                break;
            case R.id.ll_danger_stop_department:
                initDepartmentPop();
                break;
            case R.id.ll_danger_stop_day:
                initDaysPop();
                break;
            case R.id.ll_danger_stop_area:
                initAreasPop();
                break;
            case R.id.ll_danger_stop_date:
                observerDate();
                break;
            case R.id.ll_tab_flow_ryfy_other:
                mTv_tab_flow_ryfy_other.setSelected(true);
                mEt_tab_flow_ryfy_other.requestFocus();
                ryfy_remark = "";
                initRyfy();
                break;
            case R.id.ll_tab_flow_ryfh_other:
                mTv_tab_flow_ryfh_other.setSelected(true);
                mEt_tab_flow_ryfh_other.requestFocus();
                ryfh_remark = "";
                initFhsb();
                break;
            case R.id.ll_tab_flow_rywz_other:
                mTv_tab_flow_rywz_other.setSelected(true);
                mEt_tab_flow_rywz_other.requestFocus();
                rywz_remark = "";
                initRywz();
                break;
            case R.id.ll_tab_flow_gjsb_other:
                mTv_tab_flow_gjsb_other.setSelected(true);
                mEt_tab_flow_gjsb_other.requestFocus();
                gjsb_remark = "";
                initGjsb();
                break;
            case R.id.ll_tab_flow_cx_other:
                mTv_tab_flow_cx_other.setSelected(true);
                mEt_tab_flow_cx_other.requestFocus();
                cx_remark = "";
                initCx();
                break;
            case R.id.ll_tab_flow_cxbz_other:
                mTv_tab_flow_cxbz_other.setSelected(true);
                mEt_tab_flow_cxbz_other.requestFocus();
                cxbz_remark = "";
                initCxbz();
                break;
        }
    }

    /**
     * stop 详情
     */
    private void initStopDetail() {
        Call<String> call = HttpManager.getInstance().requestService().DANGER_STOP_DETAIL(id);
        HttpManager.getInstance().requestCallBack(call, new CommonCallBack<String>() {
            @Override
            public void requestSuccess(String result) {
                DangerStopDetailOutput dangerStopDetailOutput= new Gson().fromJson(result, DangerStopDetailOutput.class);
                if (dangerStopDetailOutput.getResult().equals("Success")) {
                    final DangerStopDetailOutput.DataBean dataBean = dangerStopDetailOutput.getData();
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            // 是否皆安全
                            evaluationc = dataBean.isEvaluationc();
                            if (evaluationc) {
                                mTv_danger_stop_safe.setText("是");
                            } else {
                                mTv_danger_stop_safe.setText("否");
                            }
                            // 观察人
                            observePeopleId = dataBean.getObservePeople();
                            for (TrainPersonOutput.DataBean.PageDataBean trainPerson : MyApplication.getInstance().mListTrainPerson) {
                                if (trainPerson.getId().equals(observePeopleId)) {
                                    mTv_danger_stop_obsever.setText(trainPerson.getName());
                                }
                            }
                            // 部门
                            departmentId = dataBean.getDepartment();
                            for (DropDownOutput.DataBean.DataDicListBean.ValueBean valueBean : MyApplication.getInstance().mDangerDepartList) {
                                if (valueBean.getKey().equals(departmentId)) {
                                    mTv_danger_stop_department.setText(valueBean.getValue());
                                }
                            }
                            // 班次
                            shiftsId = dataBean.getShifts();
                            for (DropDownOutput.DataBean.DataDicListBean.ValueBean valueBean : MyApplication.getInstance().mDangerDaysList) {
                                if (valueBean.getKey().equals(shiftsId)) {
                                    mTv_danger_stop_day.setText(valueBean.getValue());
                                }
                            }
                            // 区域
                            situationId = dataBean.getSituation();
                            for (DropDownOutput.DataBean.DataDicListBean.ValueBean valueBean : MyApplication.getInstance().mDangerAreasList) {
                                if (valueBean.getKey().equals(situationId)) {
                                    mTv_danger_stop_area.setText(valueBean.getValue());
                                }
                            }
                            // 时间
                            mTv_danger_stop_date.setText(dataBean.getObservaDate());
                            // 人员反应
                            ryfy_remark = dataBean.getRyfy_remark();
                            ryfh_remark = dataBean.getGrfhzb_remark();
                            rywz_remark=dataBean.getRydwz_remark();
                            gjsb_remark=dataBean.getGjjsb_remark();
                            cx_remark=dataBean.getCx_remark();
                            cxbz_remark=dataBean.getZxbz_remark();

                            initOptions(9040);
                            initOptions(9041);
                            initOptions(9042);
                            initOptions(9043);
                            initOptions(9044);
                            initOptions(9045);

                            mEt_danger_stop_safe.setText(dataBean.getEncourage());
                            mEt_danger_stop_not_safe.setText(dataBean.getCorrect());
                        }
                    });
                } else {
                    ToastUtils.getInstance().showShortToastBottom(dangerStopDetailOutput.getMessage());
                }
            }

            @Override
            public void requestError(String errorMsg) {
                initOptions(9040);
                initOptions(9041);
                initOptions(9042);
                initOptions(9043);
                initOptions(9044);
                initOptions(9045);
                ToastUtils.getInstance().showShortToastBottom(errorMsg);
            }
        });
    }

    /**
     * 是否安全-pop
     */
    private void initSafePop() {
        final List<String> mListSafe = new ArrayList<>();
        mListSafe.add("是");
        mListSafe.add("否");

        View inflate = LayoutInflater.from(DangerStopDetailActivity.this).inflate(R.layout.layout_common_more_department, null);
        RecyclerView mRecyclerView = (RecyclerView) inflate.findViewById(R.id.common_recyclerview);
        LinearLayoutManager llm = new LinearLayoutManager(DangerStopDetailActivity.this);
        mRecyclerView.setLayoutManager(llm);
        // 如果Item够简单，高度是确定的，打开FixSize将提高性能
        mRecyclerView.setHasFixedSize(true);
        // 设置Item默认动画，加也行，不加也行
        mRecyclerView.setItemAnimator(new DefaultItemAnimator());
        mRecyclerView.setNestedScrollingEnabled(false);

        CommonEmptyAdapter mCommonEmptyAdapter = new CommonEmptyAdapter(DangerStopDetailActivity.this, R.layout.layout_item_common_more_department, mListSafe);
        mCommonEmptyAdapter.setItemDataListener(new CommonEmptyAdapter.ItemDataListener<String>() {
            @Override
            public void setItemData(CommonViewHolder holder, String dataBean) {
                TextView tv_department = holder.getView(R.id.tv_department);
                tv_department.setText(dataBean);
            }
        });

        mCommonEmptyAdapter.setOnItemClickListener(new CommonEmptyAdapter.OnItemClickListener() {
            @Override
            public void setOnItemClickListener(View view, int position) {
                String content = mListSafe.get(position);
                if (content.equals("是")) {
                    evaluationc = true;
                } else {
                    evaluationc = false;
                }
                mTv_danger_stop_safe.setText(content);
                PopupWindowUtils.getInstance().closePop();
            }

            @Override
            public void setOnItemLongClickListener(View view, int position) {

            }
        });

        mRecyclerView.setAdapter(mCommonEmptyAdapter);
        PopupWindowUtils.getInstance().createScalePopupWindow(DangerStopDetailActivity.this, inflate, mLl_danger_stop_safe);
    }

    /**
     * 观察人-pop
     */
    private void initObserverPop() {
        View inflate = LayoutInflater.from(DangerStopDetailActivity.this).inflate(R.layout.layout_common_more_department, null);
        RecyclerView mRecyclerView = (RecyclerView) inflate.findViewById(R.id.common_recyclerview);
        LinearLayoutManager llm = new LinearLayoutManager(DangerStopDetailActivity.this);
        mRecyclerView.setLayoutManager(llm);
        // 如果Item够简单，高度是确定的，打开FixSize将提高性能
        mRecyclerView.setHasFixedSize(true);
        // 设置Item默认动画，加也行，不加也行
        mRecyclerView.setItemAnimator(new DefaultItemAnimator());
        mRecyclerView.setNestedScrollingEnabled(false);

        CommonEmptyAdapter mCommonEmptyAdapter = new CommonEmptyAdapter(DangerStopDetailActivity.this, R.layout.layout_item_common_more_department, MyApplication.getInstance().mListTrainPerson);
        mCommonEmptyAdapter.setItemDataListener(new CommonEmptyAdapter.ItemDataListener<TrainPersonOutput.DataBean.PageDataBean>() {
            @Override
            public void setItemData(CommonViewHolder holder, TrainPersonOutput.DataBean.PageDataBean dataBean) {
                TextView tv_department = holder.getView(R.id.tv_department);
                tv_department.setText(dataBean.getName());
            }
        });

        mCommonEmptyAdapter.setOnItemClickListener(new CommonEmptyAdapter.OnItemClickListener() {
            @Override
            public void setOnItemClickListener(View view, int position) {
                TrainPersonOutput.DataBean.PageDataBean pageDataBean = MyApplication.getInstance().mListTrainPerson.get(position);
                observePeopleId = pageDataBean.getId();
                mTv_danger_stop_obsever.setText(pageDataBean.getName());
                PopupWindowUtils.getInstance().closePop();
            }

            @Override
            public void setOnItemLongClickListener(View view, int position) {

            }
        });

        mRecyclerView.setAdapter(mCommonEmptyAdapter);
        PopupWindowUtils.getInstance().createScalePopupWindow(DangerStopDetailActivity.this, inflate, mLl_danger_stop_obsever);
    }

    /**
     * 部门-pop
     */
    private void initDepartmentPop() {
        View inflate = LayoutInflater.from(DangerStopDetailActivity.this).inflate(R.layout.layout_common_more_department, null);
        RecyclerView mRecyclerView = (RecyclerView) inflate.findViewById(R.id.common_recyclerview);
        LinearLayoutManager llm = new LinearLayoutManager(DangerStopDetailActivity.this);
        mRecyclerView.setLayoutManager(llm);
        // 如果Item够简单，高度是确定的，打开FixSize将提高性能
        mRecyclerView.setHasFixedSize(true);
        // 设置Item默认动画，加也行，不加也行
        mRecyclerView.setItemAnimator(new DefaultItemAnimator());
        mRecyclerView.setNestedScrollingEnabled(false);

        CommonEmptyAdapter mCommonEmptyAdapter = new CommonEmptyAdapter(DangerStopDetailActivity.this, R.layout.layout_item_common_more_department, MyApplication.getInstance().mDangerDepartList);
        mCommonEmptyAdapter.setItemDataListener(new CommonEmptyAdapter.ItemDataListener<DropDownOutput.DataBean.DataDicListBean.ValueBean>() {
            @Override
            public void setItemData(CommonViewHolder holder, DropDownOutput.DataBean.DataDicListBean.ValueBean dataBean) {
                TextView tv_department = holder.getView(R.id.tv_department);
                tv_department.setText(dataBean.getValue());
            }
        });

        mCommonEmptyAdapter.setOnItemClickListener(new CommonEmptyAdapter.OnItemClickListener() {
            @Override
            public void setOnItemClickListener(View view, int position) {
                DropDownOutput.DataBean.DataDicListBean.ValueBean valueBean = MyApplication.getInstance().mDangerDepartList.get(position);
                departmentId = valueBean.getKey();
                mTv_danger_stop_department.setText(valueBean.getValue());
                PopupWindowUtils.getInstance().closePop();
            }

            @Override
            public void setOnItemLongClickListener(View view, int position) {

            }
        });

        mRecyclerView.setAdapter(mCommonEmptyAdapter);
        PopupWindowUtils.getInstance().createScalePopupWindow(DangerStopDetailActivity.this, inflate, mLl_danger_stop_department);
    }

    /**
     * 班次-pop
     */
    private void initDaysPop() {
        View inflate = LayoutInflater.from(DangerStopDetailActivity.this).inflate(R.layout.layout_common_more_department, null);
        RecyclerView mRecyclerView = (RecyclerView) inflate.findViewById(R.id.common_recyclerview);
        LinearLayoutManager llm = new LinearLayoutManager(DangerStopDetailActivity.this);
        mRecyclerView.setLayoutManager(llm);
        // 如果Item够简单，高度是确定的，打开FixSize将提高性能
        mRecyclerView.setHasFixedSize(true);
        // 设置Item默认动画，加也行，不加也行
        mRecyclerView.setItemAnimator(new DefaultItemAnimator());
        mRecyclerView.setNestedScrollingEnabled(false);

        CommonEmptyAdapter mCommonEmptyAdapter = new CommonEmptyAdapter(DangerStopDetailActivity.this, R.layout.layout_item_common_more_department, MyApplication.getInstance().mDangerDaysList);
        mCommonEmptyAdapter.setItemDataListener(new CommonEmptyAdapter.ItemDataListener<DropDownOutput.DataBean.DataDicListBean.ValueBean>() {
            @Override
            public void setItemData(CommonViewHolder holder, DropDownOutput.DataBean.DataDicListBean.ValueBean dataBean) {
                TextView tv_department = holder.getView(R.id.tv_department);
                tv_department.setText(dataBean.getValue());
            }
        });

        mCommonEmptyAdapter.setOnItemClickListener(new CommonEmptyAdapter.OnItemClickListener() {
            @Override
            public void setOnItemClickListener(View view, int position) {
                DropDownOutput.DataBean.DataDicListBean.ValueBean valueBean = MyApplication.getInstance().mDangerDaysList.get(position);
                shiftsId = valueBean.getKey();
                mTv_danger_stop_day.setText(valueBean.getValue());
                PopupWindowUtils.getInstance().closePop();
            }

            @Override
            public void setOnItemLongClickListener(View view, int position) {

            }
        });

        mRecyclerView.setAdapter(mCommonEmptyAdapter);
        PopupWindowUtils.getInstance().createScalePopupWindow(DangerStopDetailActivity.this, inflate, mLl_danger_stop_day);
    }

    /**
     * 区域-pop
     */
    private void initAreasPop() {
        View inflate = LayoutInflater.from(DangerStopDetailActivity.this).inflate(R.layout.layout_common_more_department, null);
        RecyclerView mRecyclerView = (RecyclerView) inflate.findViewById(R.id.common_recyclerview);
        LinearLayoutManager llm = new LinearLayoutManager(DangerStopDetailActivity.this);
        mRecyclerView.setLayoutManager(llm);
        // 如果Item够简单，高度是确定的，打开FixSize将提高性能
        mRecyclerView.setHasFixedSize(true);
        // 设置Item默认动画，加也行，不加也行
        mRecyclerView.setItemAnimator(new DefaultItemAnimator());
        mRecyclerView.setNestedScrollingEnabled(false);

        CommonEmptyAdapter mCommonEmptyAdapter = new CommonEmptyAdapter(DangerStopDetailActivity.this, R.layout.layout_item_common_more_department, MyApplication.getInstance().mDangerAreasList);
        mCommonEmptyAdapter.setItemDataListener(new CommonEmptyAdapter.ItemDataListener<DropDownOutput.DataBean.DataDicListBean.ValueBean>() {
            @Override
            public void setItemData(CommonViewHolder holder, DropDownOutput.DataBean.DataDicListBean.ValueBean dataBean) {
                TextView tv_department = holder.getView(R.id.tv_department);
                tv_department.setText(dataBean.getValue());
            }
        });

        mCommonEmptyAdapter.setOnItemClickListener(new CommonEmptyAdapter.OnItemClickListener() {
            @Override
            public void setOnItemClickListener(View view, int position) {
                DropDownOutput.DataBean.DataDicListBean.ValueBean valueBean = MyApplication.getInstance().mDangerAreasList.get(position);
                situationId = valueBean.getKey();
                mTv_danger_stop_area.setText(valueBean.getValue());
                PopupWindowUtils.getInstance().closePop();
            }

            @Override
            public void setOnItemLongClickListener(View view, int position) {

            }
        });

        mRecyclerView.setAdapter(mCommonEmptyAdapter);
        PopupWindowUtils.getInstance().createScalePopupWindow(DangerStopDetailActivity.this, inflate, mLl_danger_stop_area);
    }

    /**
     * 观察日期
     */
    private void observerDate() {
        Calendar selectedDate = Calendar.getInstance();
        Calendar startDate = Calendar.getInstance();
        Calendar endDate = Calendar.getInstance();

        startDate.set(1949, 1, 1);
        String currentYMD = DateTimeUtils.getCurrentYMD();
        String[] split = currentYMD.split("-");
        selectedDate.set(Integer.parseInt(split[0]), Integer.parseInt(split[1]) - 1, Integer.parseInt(split[2]));
        endDate.set(Integer.parseInt(split[0]), Integer.parseInt(split[1]) - 1, Integer.parseInt(split[2]));

        //时间选择器
        TimePickerView pvTime = new TimePickerBuilder(DangerStopDetailActivity.this, new OnTimeSelectListener() {
            @Override
            public void onTimeSelect(Date date, View v) {
                SimpleDateFormat sdf_ymd = new SimpleDateFormat("yyyy-MM-dd HH:mm");
                mTv_danger_stop_date.setText(sdf_ymd.format(date));
            }
        })
                .setDate(selectedDate)
                .setRangDate(startDate, endDate)//起始终止年月日设定
                .build();

        pvTime.show();
    }

    /**
     * 初始化option
     *
     * @param code
     */
    private void initOptions(final int code) {
        DropDownInput dropDownInput = new DropDownInput();
        List<String> categoryList = new ArrayList<>();
        categoryList.add(String.valueOf(code));
        List<String> functionList = new ArrayList<>();
        dropDownInput.setCategoryCodeArray(categoryList);
        dropDownInput.setFunctionCodeArray(functionList);
        dropDownInput.setIsGetFactoryList(false);

        Call<String> call = HttpManager.getInstance().requestService().DROP_DOWN(HttpManager.getInstance().requestBody(dropDownInput));
        HttpManager.getInstance().requestCallBack(call, new CommonCallBack<String>() {
            @Override
            public void requestSuccess(String result) {
                DropDownOutput dropDownOutput = new Gson().fromJson(result, DropDownOutput.class);
                if (dropDownOutput.getResult().equals("Success")) {
                    List<DropDownOutput.DataBean.DataDicListBean> dataDicList = dropDownOutput.getData().getDataDicList();
                    for (DropDownOutput.DataBean.DataDicListBean dataDicListBean : dataDicList) {
                        List<DropDownOutput.DataBean.DataDicListBean.ValueBean> valueBeanList = dataDicListBean.getValue();
                        switch (code) {
                            case 9040:
                                mDangerRyfyList.addAll(valueBeanList);
                                initRyfy();
                                break;
                            case 9041:
                                mDangerRyfhList.addAll(valueBeanList);
                                initFhsb();
                                break;
                            case 9042:
                                mDangerRywzList.addAll(valueBeanList);
                                initRywz();
                                break;
                            case 9043:
                                mDangerGjsbList.addAll(valueBeanList);
                                initGjsb();
                                break;
                            case 9044:
                                mDangerCxList.addAll(valueBeanList);
                                initCx();
                                break;
                            case 9045:
                                mDangerCxbzList.addAll(valueBeanList);
                                initCxbz();
                                break;
                        }
                    }
                } else {
                    ToastUtils.getInstance().showShortToastBottom(dropDownOutput.getMessage());
                }
            }

            @Override
            public void requestError(String errorMsg) {
                ToastUtils.getInstance().showShortToastBottom(errorMsg);
            }
        });
    }

    /**
     * 人员反应
     */
    private void initRyfy() {
        DropDownOutput.DataBean.DataDicListBean.ValueBean valueBean = new DropDownOutput.DataBean.DataDicListBean.ValueBean();
        valueBean.setValue("");
        mDangerRyfyList.add(valueBean);

        //预先设置选中
        mTagRyfyAdapter = new TagAdapter<DropDownOutput.DataBean.DataDicListBean.ValueBean>(mDangerRyfyList) {

            @Override
            public View getView(FlowLayout parent, int position, DropDownOutput.DataBean.DataDicListBean.ValueBean bean) {
                View view = LayoutInflater.from(DangerStopDetailActivity.this).inflate(R.layout.layout_danger_stop_ryfy, null);
                TextView tv_tab_flow_msg = (TextView) view.findViewById(R.id.tv_tab_flow_msg);
                Drawable drawable = getResources().getDrawable(R.drawable.cb_examination_bg);
                // 设置图片的大小
                drawable.setBounds(0, 0, 45, 45);
                // 设置图片的位置，左、上、右、下
                if (!TextUtils.isEmpty(bean.getValue())) {
                    tv_tab_flow_msg.setCompoundDrawables(drawable, null, null, null);
                    tv_tab_flow_msg.setCompoundDrawablePadding(10);
                    tv_tab_flow_msg.setText(bean.getValue());
                }
                return tv_tab_flow_msg;
            }

            @Override
            public boolean setSelected(int position, DropDownOutput.DataBean.DataDicListBean.ValueBean bean) {
                if (TextUtils.isEmpty(ryfy_remark)) {
                    return false;
                } else {
                    return bean.getValue().equals(ryfy_remark);
                }
            }
        };
        mTagRyfyAdapter.setSelectedList(mDangerRyfyList.size() - 1);
        mFlowlayout_ryfy.setAdapter(mTagRyfyAdapter);

        mFlowlayout_ryfy.setOnTagClickListener(new TagFlowLayout.OnTagClickListener() {
            @Override
            public boolean onTagClick(View view, int position, FlowLayout parent) {
                ryfy_remark = mDangerRyfyList.get(position).getValue();
                mTagRyfyAdapter.notifyDataChanged();
                mTv_tab_flow_ryfy_other.setSelected(false);
                mEt_tab_flow_ryfy_other.clearFocus();
                // view.setVisibility(View.GONE);
                return true;
            }
        });


        mFlowlayout_ryfy.setOnSelectListener(new TagFlowLayout.OnSelectListener() {
            @Override
            public void onSelected(Set<Integer> selectPosSet) {
                // ToastUtils.getInstance().showShortToast(selectPosSet.toString());
            }
        });
    }

    /**
     * 防护设备
     */
    private void initFhsb() {
        DropDownOutput.DataBean.DataDicListBean.ValueBean valueBean = new DropDownOutput.DataBean.DataDicListBean.ValueBean();
        valueBean.setValue("");
        mDangerRyfhList.add(valueBean);

        //预先设置选中
        mTagRyfhAdapter = new TagAdapter<DropDownOutput.DataBean.DataDicListBean.ValueBean>(mDangerRyfhList) {

            @Override
            public View getView(FlowLayout parent, int position, DropDownOutput.DataBean.DataDicListBean.ValueBean bean) {
                View view = LayoutInflater.from(DangerStopDetailActivity.this).inflate(R.layout.layout_danger_stop_ryfy, null);
                TextView tv_tab_flow_msg = (TextView) view.findViewById(R.id.tv_tab_flow_msg);
                Drawable drawable = getResources().getDrawable(R.drawable.cb_examination_bg);
                // 设置图片的大小
                drawable.setBounds(0, 0, 45, 45);
                // 设置图片的位置，左、上、右、下
                if (!TextUtils.isEmpty(bean.getValue())) {
                    tv_tab_flow_msg.setCompoundDrawables(drawable, null, null, null);
                    tv_tab_flow_msg.setCompoundDrawablePadding(10);
                    tv_tab_flow_msg.setText(bean.getValue());
                }
                return tv_tab_flow_msg;
            }

            @Override
            public boolean setSelected(int position, DropDownOutput.DataBean.DataDicListBean.ValueBean s) {
                if (TextUtils.isEmpty(ryfh_remark)) {
                    return false;
                } else {
                    return s.getValue().equals(ryfh_remark);
                }
            }
        };
        mTagRyfhAdapter.setSelectedList(mDangerRyfhList.size() - 1);
        mFlowlayout_ryfh.setAdapter(mTagRyfhAdapter);

        mFlowlayout_ryfh.setOnTagClickListener(new TagFlowLayout.OnTagClickListener() {
            @Override
            public boolean onTagClick(View view, int position, FlowLayout parent) {
                ryfh_remark = mDangerRyfhList.get(position).getValue();
                mTagRyfhAdapter.notifyDataChanged();
                mTv_tab_flow_ryfh_other.setSelected(false);
                mEt_tab_flow_ryfh_other.clearFocus();
                // view.setVisibility(View.GONE);
                return true;
            }
        });


        mFlowlayout_ryfh.setOnSelectListener(new TagFlowLayout.OnSelectListener() {
            @Override
            public void onSelected(Set<Integer> selectPosSet) {
                // ToastUtils.getInstance().showShortToast(selectPosSet.toString());
            }
        });
    }

    /**
     * 人员位置
     */
    private void initRywz() {
        DropDownOutput.DataBean.DataDicListBean.ValueBean valueBean = new DropDownOutput.DataBean.DataDicListBean.ValueBean();
        valueBean.setValue("");
        mDangerRywzList.add(valueBean);

        //预先设置选中
        mTagRywzAdapter = new TagAdapter<DropDownOutput.DataBean.DataDicListBean.ValueBean>(mDangerRywzList) {

            @Override
            public View getView(FlowLayout parent, int position, DropDownOutput.DataBean.DataDicListBean.ValueBean bean) {
                View view = LayoutInflater.from(DangerStopDetailActivity.this).inflate(R.layout.layout_danger_stop_ryfy, null);
                TextView tv_tab_flow_msg = (TextView) view.findViewById(R.id.tv_tab_flow_msg);
                Drawable drawable = getResources().getDrawable(R.drawable.cb_examination_bg);
                // 设置图片的大小
                drawable.setBounds(0, 0, 45, 45);
                // 设置图片的位置，左、上、右、下
                if (!TextUtils.isEmpty(bean.getValue())) {
                    tv_tab_flow_msg.setCompoundDrawables(drawable, null, null, null);
                    tv_tab_flow_msg.setCompoundDrawablePadding(10);
                    tv_tab_flow_msg.setText(bean.getValue());
                }
                return tv_tab_flow_msg;
            }

            @Override
            public boolean setSelected(int position, DropDownOutput.DataBean.DataDicListBean.ValueBean s) {
                if (TextUtils.isEmpty(rywz_remark)) {
                    return false;
                } else {
                    return s.getValue().equals(rywz_remark);
                }
            }
        };
        mTagRywzAdapter.setSelectedList(mDangerRywzList.size() - 1);
        mFlowlayout_rywz.setAdapter(mTagRywzAdapter);

        mFlowlayout_rywz.setOnTagClickListener(new TagFlowLayout.OnTagClickListener() {
            @Override
            public boolean onTagClick(View view, int position, FlowLayout parent) {
                rywz_remark = mDangerRywzList.get(position).getValue();
                mTagRywzAdapter.notifyDataChanged();
                mTv_tab_flow_rywz_other.setSelected(false);
                mEt_tab_flow_rywz_other.clearFocus();
                // view.setVisibility(View.GONE);
                return true;
            }
        });


        mFlowlayout_rywz.setOnSelectListener(new TagFlowLayout.OnSelectListener() {
            @Override
            public void onSelected(Set<Integer> selectPosSet) {
                // ToastUtils.getInstance().showShortToast(selectPosSet.toString());
            }
        });
    }

    /**
     * 工具设备
     */
    private void initGjsb() {
        DropDownOutput.DataBean.DataDicListBean.ValueBean valueBean = new DropDownOutput.DataBean.DataDicListBean.ValueBean();
        valueBean.setValue("");
        mDangerGjsbList.add(valueBean);

        //预先设置选中
        mTagGjsbAdapter = new TagAdapter<DropDownOutput.DataBean.DataDicListBean.ValueBean>(mDangerGjsbList) {

            @Override
            public View getView(FlowLayout parent, int position, DropDownOutput.DataBean.DataDicListBean.ValueBean bean) {
                View view = LayoutInflater.from(DangerStopDetailActivity.this).inflate(R.layout.layout_danger_stop_ryfy, null);
                TextView tv_tab_flow_msg = (TextView) view.findViewById(R.id.tv_tab_flow_msg);
                Drawable drawable = getResources().getDrawable(R.drawable.cb_examination_bg);
                // 设置图片的大小
                drawable.setBounds(0, 0, 45, 45);
                // 设置图片的位置，左、上、右、下
                if (!TextUtils.isEmpty(bean.getValue())) {
                    tv_tab_flow_msg.setCompoundDrawables(drawable, null, null, null);
                    tv_tab_flow_msg.setCompoundDrawablePadding(10);
                    tv_tab_flow_msg.setText(bean.getValue());
                }
                return tv_tab_flow_msg;
            }

            @Override
            public boolean setSelected(int position, DropDownOutput.DataBean.DataDicListBean.ValueBean s) {
                if (TextUtils.isEmpty(gjsb_remark)) {
                    return false;
                } else {
                    return s.getValue().equals(gjsb_remark);
                }
            }
        };
        mTagGjsbAdapter.setSelectedList(mDangerGjsbList.size() - 1);
        mFlowlayout_gjsb.setAdapter(mTagGjsbAdapter);

        mFlowlayout_gjsb.setOnTagClickListener(new TagFlowLayout.OnTagClickListener() {
            @Override
            public boolean onTagClick(View view, int position, FlowLayout parent) {
                gjsb_remark = mDangerGjsbList.get(position).getValue();
                mTagGjsbAdapter.notifyDataChanged();
                mTv_tab_flow_gjsb_other.setSelected(false);
                mEt_tab_flow_gjsb_other.clearFocus();
                // view.setVisibility(View.GONE);
                return true;
            }
        });


        mFlowlayout_gjsb.setOnSelectListener(new TagFlowLayout.OnSelectListener() {
            @Override
            public void onSelected(Set<Integer> selectPosSet) {
                // ToastUtils.getInstance().showShortToast(selectPosSet.toString());
            }
        });
    }

    /**
     * 程序
     */
    private void initCx() {
        DropDownOutput.DataBean.DataDicListBean.ValueBean valueBean = new DropDownOutput.DataBean.DataDicListBean.ValueBean();
        valueBean.setValue("");
        mDangerCxList.add(valueBean);

        //预先设置选中
        mTagCxAdapter = new TagAdapter<DropDownOutput.DataBean.DataDicListBean.ValueBean>(mDangerCxList) {

            @Override
            public View getView(FlowLayout parent, int position, DropDownOutput.DataBean.DataDicListBean.ValueBean bean) {
                View view = LayoutInflater.from(DangerStopDetailActivity.this).inflate(R.layout.layout_danger_stop_ryfy, null);
                TextView tv_tab_flow_msg = (TextView) view.findViewById(R.id.tv_tab_flow_msg);
                Drawable drawable = getResources().getDrawable(R.drawable.cb_examination_bg);
                // 设置图片的大小
                drawable.setBounds(0, 0, 45, 45);
                // 设置图片的位置，左、上、右、下
                if (!TextUtils.isEmpty(bean.getValue())) {
                    tv_tab_flow_msg.setCompoundDrawables(drawable, null, null, null);
                    tv_tab_flow_msg.setCompoundDrawablePadding(10);
                    tv_tab_flow_msg.setText(bean.getValue());
                }
                return tv_tab_flow_msg;
            }

            @Override
            public boolean setSelected(int position, DropDownOutput.DataBean.DataDicListBean.ValueBean s) {
                if (TextUtils.isEmpty(cx_remark)) {
                    return false;
                } else {
                    return s.getValue().equals(cx_remark);
                }
            }
        };
        mTagCxAdapter.setSelectedList(mDangerCxList.size() - 1);
        mFlowlayout_cx.setAdapter(mTagCxAdapter);

        mFlowlayout_cx.setOnTagClickListener(new TagFlowLayout.OnTagClickListener() {
            @Override
            public boolean onTagClick(View view, int position, FlowLayout parent) {
                cx_remark = mDangerCxList.get(position).getValue();
                mTagCxAdapter.notifyDataChanged();
                mTv_tab_flow_cx_other.setSelected(false);
                mEt_tab_flow_cx_other.clearFocus();
                // view.setVisibility(View.GONE);
                return true;
            }
        });


        mFlowlayout_cx.setOnSelectListener(new TagFlowLayout.OnSelectListener() {
            @Override
            public void onSelected(Set<Integer> selectPosSet) {
                // ToastUtils.getInstance().showShortToast(selectPosSet.toString());
            }
        });
    }

    /**
     * 程序标准
     */
    private void initCxbz() {
        DropDownOutput.DataBean.DataDicListBean.ValueBean valueBean = new DropDownOutput.DataBean.DataDicListBean.ValueBean();
        valueBean.setValue("");
        mDangerCxbzList.add(valueBean);

        //预先设置选中
        mTagCxbzAdapter = new TagAdapter<DropDownOutput.DataBean.DataDicListBean.ValueBean>(mDangerCxbzList) {

            @Override
            public View getView(FlowLayout parent, int position, DropDownOutput.DataBean.DataDicListBean.ValueBean bean) {
                View view = LayoutInflater.from(DangerStopDetailActivity.this).inflate(R.layout.layout_danger_stop_ryfy, null);
                TextView tv_tab_flow_msg = (TextView) view.findViewById(R.id.tv_tab_flow_msg);
                Drawable drawable = getResources().getDrawable(R.drawable.cb_examination_bg);
                // 设置图片的大小
                drawable.setBounds(0, 0, 45, 45);
                // 设置图片的位置，左、上、右、下
                if (!TextUtils.isEmpty(bean.getValue())) {
                    tv_tab_flow_msg.setCompoundDrawables(drawable, null, null, null);
                    tv_tab_flow_msg.setCompoundDrawablePadding(10);
                    tv_tab_flow_msg.setText(bean.getValue());
                }
                return tv_tab_flow_msg;
            }

            @Override
            public boolean setSelected(int position, DropDownOutput.DataBean.DataDicListBean.ValueBean s) {
                if (TextUtils.isEmpty(cxbz_remark)) {
                    return false;
                } else {
                    return s.getValue().equals(cxbz_remark);
                }
            }
        };
        mTagCxbzAdapter.setSelectedList(mDangerCxbzList.size() - 1);
        mFlowlayout_cxbz.setAdapter(mTagCxbzAdapter);

        mFlowlayout_cxbz.setOnTagClickListener(new TagFlowLayout.OnTagClickListener() {
            @Override
            public boolean onTagClick(View view, int position, FlowLayout parent) {
                cxbz_remark = mDangerCxbzList.get(position).getValue();
                mTagCxbzAdapter.notifyDataChanged();
                mTv_tab_flow_cxbz_other.setSelected(false);
                mEt_tab_flow_cxbz_other.clearFocus();
                // view.setVisibility(View.GONE);
                return true;
            }
        });


        mFlowlayout_cxbz.setOnSelectListener(new TagFlowLayout.OnSelectListener() {
            @Override
            public void onSelected(Set<Integer> selectPosSet) {
                // ToastUtils.getInstance().showShortToast(selectPosSet.toString());
            }
        });
    }

}
